﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using StellarMedical.ServiceReference;
using StellarMedical.DuplexServiceReference;
using System.ServiceModel;

namespace StellarMedical
{
    public class ServiceConfig
    {

        public static DuplexServiceClient DuplexConnect()
        {
            Uri uri = System.Windows.Browser.HtmlPage.Document.DocumentUri;
            string host = uri.Host;
            host = "http://" + host;
            string servicePath = "";

            if (host.Contains("localhost"))
            {
                servicePath = Config.Service.LOCAL_DUPLEX_SERVICE_PATH;
            }
            else
            {
                servicePath = Config.Service.REMOTE_DUPLEX_SERVICE_PATH;
            }

            string serviceUri = host + servicePath;

            PollingDuplexHttpBinding binding = new PollingDuplexHttpBinding();

            binding.MaxBufferSize = Config.Service.SERVICE_MAX_BUFFER_SIZE;
            binding.MaxReceivedMessageSize = Config.Service.SERVICE_MAX_RECEIVE_BUFFER_SIZE;

            return new DuplexServiceClient(binding, new System.ServiceModel.EndpointAddress(serviceUri));
        }

        public static MedicalServiceClient Connect()
        {
            Uri uri = System.Windows.Browser.HtmlPage.Document.DocumentUri;
            string host = uri.Host;
            host = "http://" + host; 
            string servicePath = "";
            if (host.Contains("localhost"))
            {
                // it is local
                servicePath = Config.Service.LOCAL_SERVICE_PATH;
            }
            else
            {
                // it is remote
                servicePath = Config.Service.REMOTE_SERVICE_PATH;
            }
            string serviceUri = host + servicePath;
            System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
            binding.MaxBufferSize = Config.Service.SERVICE_MAX_BUFFER_SIZE;
            binding.MaxReceivedMessageSize = Config.Service.SERVICE_MAX_RECEIVE_BUFFER_SIZE;
            

            return new MedicalServiceClient(binding, new System.ServiceModel.EndpointAddress(serviceUri));
        }
    }
}
